package com.example.douyinproject.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.example.douyinproject.R;

public class MeFragment extends Fragment {
    EditText userName,passWord;
    Button loginButton,signUpButton;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_me, container, false);

        // 关联用户名、密码和登录、注册按钮
        userName = view.findViewById(R.id.UserNameEdit);
        passWord = view.findViewById(R.id.PassWordEdit);
        loginButton = view.findViewById(R.id.LoginButton);
        signUpButton = view.findViewById(R.id.SignUpButton);

        // 登录按钮监听器
        loginButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 获取用户名和密码
                        String strUserName = userName.getText().toString().trim();
                        String strPassWord = passWord.getText().toString().trim();
                        // 判断如果用户名为"root"密码为"root"则登录成功
                        if (strUserName.equals("root") && strPassWord.equals("root")) {
                            Toast.makeText(getActivity(), "登录成功！", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(getContext(), PersonalHomePage.class);
                            startActivity(intent);
                        } else {
                            Toast.makeText(getActivity(), "用户名或密码有误！请输入正确的用户名或密码！", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
        );
        // 注册按钮监听器
        signUpButton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 跳转到注册界面
                        Intent intent = new Intent(getContext(), Register.class);
                        startActivity(intent);
                    }
                }
        );

        return view;
    }
}